<template>
  <div id="activeTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="选择学院" prop="categoryId">
          <el-select v-model="formInline.id" clearable>
            <el-option
              v-for="item in collegeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标题" prop="activityId">
          <el-input
            v-model="formInline.name"
            placeholder="请输入标题"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch()">
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'activeTopSearch',
  msg: '活动分析-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          id: '',
          name: ''
        }
      }
    }
  },
  data() {
    return {
      collegeList: [
        // 学院
        { dictLabel: '全部学院', dictValue: '' }
      ],
      rules: {
        activityId: {},
        type: {},
        createTime: { type: 'array' }
      }
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startDate = newVal[0]
          this.formInline.endDate = newVal[1]
        } else {
          this.formInline.startDate = ''
          this.formInline.endDate = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    /* 获取数据状态 */
    async getStatusList() {
      // 学院
      let data2 = await sysNormalDisable('sys_college', 'LVideocollegeType')
      this.collegeList = this.collegeList.concat(data2)
      //设置默认数据
      this.setDefaultValue()
      //触发获取列表
      this.$emit('toSearch')
    },
    /* 搜索 */
    toSearch(formName) {
      this.$emit('toSearch')
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      this.setDefaultValue()
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.id = this.collegeList[0].dictValue
      this.formInline.name = ''
    }
  }
}
</script>

<style lang="less"></style>
